package pl.edu.pw.perg.compinfodb.ui;

import javax.swing.event.TableModelEvent;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

import org.jdesktop.swingx.JXTable;

import pl.edu.pw.perg.compinfodb.datamodel.CableDetailsTableModel;
import pl.edu.pw.perg.compinfodb.datamodel.ElementTableModel;
import pl.edu.pw.perg.compinfodb.datamodel.SearchTableModel;

public class CustomRendererTableFactory {

	private ColorRenderer renderer = new ColorRenderer();
	public CustomRendererTableFactory() {
		
	}
	
	@SuppressWarnings("serial")
	public JXTable getTable(TableModel tm){ 
		JXTable table = new JXTable(tm)
//		{
//			@Override
//			public void tableChanged(TableModelEvent e) {
//				super.tableChanged(e);
////				for (int i = 0; i < getColumnCount(); i++) {
////					getColumnModel().getColumn(i).setCellRenderer(
////							renderer);
////				}
//				packAll();
//			}
//		
//		}
		;
		
		for (TableColumn column : table.getColumns()) {
			column.setCellRenderer(renderer);
		}
		table.packAll();
//		table.setColumnControlVisible(true);
//		table.setAutoCreateColumnsFromModel(false);
//		table.setAutoCreateRowSorter(true);
		return table;
	}

	public JXTable getElementTable(ElementTableModel tm){
		JXTable table = getTable(tm);
		table.getSelectionModel().addListSelectionListener(tm);
		return table;
	}

	public JXTable getElementTable(CableDetailsTableModel cableDetailsTableModel) {
		JXTable table = getTable(cableDetailsTableModel);
		table.getSelectionModel().addListSelectionListener(cableDetailsTableModel);
		return table;
	}
	
	public JXTable getSearchTable(SearchTableModel stm){
		return new JXTable();
	}
}
